class Solution {
public:
    string longestDiverseString(int a, int b, int c) {
        string res = "";
        priority_queue<pair<int, char>> pq;
        if (a) pq.push(make_pair(a, 'a'));
        if (b) pq.push(make_pair(b, 'b'));
        if (c) pq.push(make_pair(c, 'c'));
        while (!pq.empty()) {
            int mi = pq.top().first;
            char mc = pq.top().second;
            pq.pop();
            int add = (!res.empty() && res.back() == mc) ? 1 : min(2, mi);
            res += string(add, mc);
            mi -= add;
            if (pq.empty()) break;
            int smi = pq.top().first;
            char smc = pq.top().second;
            pq.pop();
            res += smc;
            smi -= 1;
            if (mi) pq.push(make_pair(mi, mc));
            if (smi) pq.push(make_pair(smi, smc));
        }
        return res;
    }
};